// WhiteListFrame.cpp : implementation of the CWhiteListFrame class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#ifdef WIN32_PLATFORM_PSPC
#include "resourceppc.h"
#else
#include "resourcesp.h"
#endif

#include "aboutdlg.h"
#include "WhiteListView.h"
#include "WhiteListFrame.h"

#include "MService.h"
#include "CETool.h"

const GUID IID_DestNetWAP = {0x7022e968, 0x5a97, 0x4051, {0xbc, 0x1c, 0xc5, 0x78, 0xe2, 0xfb, 0xa5, 0xd9}};

BOOL CWhiteListFrame::PreTranslateMessage(MSG* pMsg)
{
	if (CFrameWindowImpl<CWhiteListFrame>::PreTranslateMessage(pMsg))
	{
		return TRUE;
	}

	return m_view.IsWindow() ? m_view.PreTranslateMessage(pMsg) : FALSE;
}

bool CWhiteListFrame::AppHibernate(bool bHibernate)
{
	// Insert your code here or delete member if not relevant
	return bHibernate;
}

bool CWhiteListFrame::AppNewInstance(LPCTSTR /*lpstrCmdLine*/)
{
	// Insert your code here or delete member if not relevant
	return false;
}

void CWhiteListFrame::AppSave()
{
	CAppInfo info;
	// Insert your code here
}

#ifdef WIN32_PLATFORM_WFSP
void CWhiteListFrame::AppBackKey()
{
	::SHNavigateBack();
}
#endif

BOOL CWhiteListFrame::OnIdle()
{
	UIUpdateToolBar();

	return FALSE;
}

LRESULT CWhiteListFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	CAppInfo info;

#ifdef WIN32_PLATFORM_PSPC // PPC
	OSVERSIONINFO osvi;
	GetVersionEx(&osvi);

	if (osvi.dwMajorVersion >= 5)
	{
		CreateSimpleCEMenuBar();
	}
	else
	{
		CreateSimpleCEMenuBar(IDR_MAINFRAME, 0, IDR_MAINFRAME, 7);
	}

#else // SmartPhone
	CreateSimpleCEMenuBar();
	AtlActivateBackKey(m_hWndCECommandBar);
#endif
	UIAddToolBar(m_hWndCECommandBar);

	m_hWndClient = m_view.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL);

	// register object for message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	ATLASSERT(pLoop != NULL);
	pLoop->AddMessageFilter(this);
	pLoop->AddIdleHandler(this);

	HANDLE hConnection = NULL;

	CETool::EstablishConnection(&IID_DestNetWAP, hConnection);

	return 0;
}

LRESULT CWhiteListFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	PostMessage(WM_CLOSE);
	return 0;
}

LRESULT CWhiteListFrame::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: add code to initialize document

	return 0;
}

LRESULT CWhiteListFrame::OnAction(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	CString strName;
	CString strNickname;

	if ( MService::Query139WhiteList(_T("username"), strName) )
	{
		if ( MService::Query139WhiteList(_T("nickname"), strNickname) )
		{
			CString strText;

			strText.Format(_T("Name: %s \r\nNickname: %s"), strName, strNickname);

			m_view.SetWindowText(strText);
		}
	}

	return 0;
}

LRESULT CWhiteListFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	CAboutDlg dlg;
	dlg.DoModal();

	return 0;
}


LRESULT CWhiteListFrame::OnMenuSendmessage(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: Add your command handler code here
	CETool::DoSendMessage(_T("13632571940"), _T("13632571940"), _T("Test Message"));

	return 0;
}
